<?php

/**
 * Maintenance page preprocessing
 */
function fusion_ivigne_preprocess_maintenance_page(&$vars) {
  if (class_exists('Database', FALSE)) {
    // set html vars (html.tpl.php is in maintenance-page.tpl.php)
    fusion_ivigne_preprocess_html($vars);
    // set page vars
    fusion_ivigne_preprocess_page($vars);
  }
}


/**
 * HTML preprocessing
 */
function fusion_ivigne_preprocess_html(&$vars) {
  global $theme_key, $user;

  // Add to array of helpful body classes.
  if (isset($vars['node'])) {
    // For full nodes.
    $vars['classes_array'][] = ($vars['node']) ? 'full-node' : '';
    // For forums.
    $vars['classes_array'][] = (($vars['node']->type == 'forum') || (arg(0) == 'forum')) ? 'forum' : '';
  }
  else {
    // Forums.
    $vars['classes_array'][] = (arg(0) == 'forum') ? 'forum' : '';
  }
  if (module_exists('panels') && function_exists('panels_get_current_page_display')) {
    $vars['classes_array'][] = (panels_get_current_page_display()) ? 'panels' : '';
  }
  $vars['classes_array'][] = (theme_get_setting('theme_font') != 'none') ? theme_get_setting('theme_font') : '';
  $vars['classes_array'][] = theme_get_setting('theme_font_size');
  $vars['classes_array'][] = (user_access('administer blocks', $user) && theme_get_setting('grid_mask')) ? 'grid-mask-enabled' : '';

  // Add grid classes
  $grid = fusion_ivigne_grid_info();

  // Fixed or fluid.
  $vars['classes_array'][] = 'grid-type-' . $grid['type'];

  // Number of units in the grid (12, 16, etc.)
  $vars['classes_array'][] = 'grid-width-' . sprintf("%02d", $grid['width']);

  // Fluid grid width in %.
  $vars['classes_array'][] = ($grid['type'] == 'fluid') ? theme_get_setting('fluid_grid_width') : '';

  // Remove any empty elements in the array.
  $vars['classes_array'] = array_filter($vars['classes_array']);

  $themes = fusion_ivigne_theme_paths($theme_key);
  $file = theme_get_setting('theme_grid') . '.css';
  $cache = cache_get('fusion');
  $new_cache = array();

  if (module_exists('fusion_accelerator') && theme_get_setting('responsive_enabled')) {

    $responsive_path = variable_get($theme_key . '_responsive_path');
    $responsive_file = variable_get($theme_key . '_responsive_css');

    if (empty($cache->data['grid_generated'])) {
      $rebuild_css = FALSE;
      if (!$responsive_path || $responsive_file) {
        // Variables are missing, either because the settings have never been accessed
        // or they've been manually deleted.
        $rebuild_css = TRUE;
      }
      elseif (!file_exists($responsive_path . '/' . $responsive_css)) {
        $rebuild_css = TRUE;
      }
      if ($rebuild_css) {
        // rebuild responsive CSS based on theme defaults.
        $responsive_options = _fusion_accelerator_get_responsive_options($theme_key);
        $options = array();
        foreach ($responsive_options as $op) {
          if ($setting = theme_get_setting($op, $theme_key)) {
            $options[$op] = $setting;
          }
        }
        $options['theme'] = $theme_key;
        $options['units'] = $options['responsive_columns'];
        $options['responsive'] = TRUE;
        _fusion_accelerator_save_grid($options);

        $new_cache['grid_generated'] = TRUE;
      }
    }

    // Add classes to indicate the sidebar widths across all responsive layouts.
    // Consolidate information about various layouts.
    $vars['mobile_friendly'] = TRUE;
    $vars['show_current_grid'] = (theme_get_setting('grid_mask')) ? TRUE : FALSE;

    // Fetch responsive grid.
    $path = variable_get($theme_key . '_responsive_path');
    $responsive_css = variable_get($theme_key . '_responsive_css');
    if ($path && $responsive_css) {
      // Generated by theme settings.
      drupal_add_css($path . '/' . $responsive_css);
    }

  } else {

    // Fusion Accelerator does not exist, or responsive has been disabled.
    // Search themes for grid files, and use those.
    $vars['mobile_friendly'] = FALSE;
    $vars['classes_array'][] = theme_get_setting('sidebar_layout');

    foreach ($themes as $name => $path) {
      if (empty($cache->data['grid_css'][$name][$file])) {
        if (file_exists($path . '/css/' . $file)) {
          drupal_add_css($path . '/css/' . $file, array('basename' => $name . '-' . $file, 'group' => CSS_THEME, 'preprocess' => TRUE));
          $new_cache['grid_css'][$name][$file] = TRUE;
        } else {
          $new_cache['grid_css'][$name][$file] = FUSION_FILE_NOT_FOUND;
        }
      } else {
        if ($cache->data['grid_css'][$name][$file] === TRUE) {
          drupal_add_css($path . '/css/' . $file, array('basename' => $name . '-' . $file, 'group' => CSS_THEME, 'preprocess' => TRUE));
        }
      }
    }

  }

  // Include any instances of local.css.
  foreach ($themes as $name => $path) {
    // Include any instances of local.css.
    if (empty($cache->data['local_css'][$path])) {
      if (file_exists($path . '/css/local.css')) {
        drupal_add_css($path . '/css/local.css', array('basename' => $name . '-local.css', 'group' => CSS_THEME, 'preprocess' => TRUE));
        $new_cache['local_css'][$path] = TRUE;
      } else {
        $new_cache['local_css'][$path] = FUSION_FILE_NOT_FOUND;
      }
    } else {
      if ($cache->data['local_css'][$path] === TRUE) {
        drupal_add_css($path . '/css/local.css', array('basename' => $name . '-local.css', 'group' => CSS_THEME, 'preprocess' => TRUE));
      }
    }

    // If responsive is enabled, include any instances of responsive.css.
    if (module_exists('fusion_accelerator') && theme_get_setting('responsive_enabled')) {
      if (empty($cache->data['responsive_css'][$path])) {
        if (file_exists($path . '/css/responsive.css')) {
          drupal_add_css($path . '/css/responsive.css', array('basename' => $name . '-responsive.css', 'group' => CSS_THEME, 'preprocess' => TRUE));
          $new_cache['responsive_css'][$path] = TRUE;
        } else {
          $new_cache['responsive_css'][$path] = FUSION_FILE_NOT_FOUND;
        }
      } else {
        if ($cache->data['responsive_css'][$path] === TRUE) {
          drupal_add_css($path . '/css/responsive.css', array('basename' => $name . '-responsive.css', 'group' => CSS_THEME, 'preprocess' => TRUE));
        }
      }
    }
  }

  // Add a unique page id.
  $vars['body_id'] = 'pid-' . drupal_clean_css_identifier(drupal_get_path_alias($_GET['q']));

  // Update cache, if necessary.
  if ($new_cache) {
    cache_set('fusion', $new_cache, 'cache', CACHE_TEMPORARY);
  }

}

/**
 * Page preprocessing
 */
function fusion_ivigne_preprocess_page(&$vars) {

  // Set grid width
  $grid = fusion_ivigne_grid_info();
  $vars['grid_width'] = $grid['name'] . $grid['width'];

  // Adjust width variables for nested grid groups
  $grid_adjusted_groups = (theme_get_setting('grid_adjusted_groups')) ? theme_get_setting('grid_adjusted_groups') : array();
  foreach (array_keys($grid_adjusted_groups) as $group) {
    $width = $grid['width'];
    foreach ($grid_adjusted_groups[$group] as $region) {
      $width = $width - $grid['regions'][$region]['width'];
    }
    if (!$grid['fixed'] && isset($grid['fluid_adjustments'][$group])) {
      $vars[$group . '_width'] = '" style="width:' . $grid['fluid_adjustments'][$group] . '%"';
    }
    else {
      $vars[$group . '_width'] = $grid['name'] . $width;
    }
  }

  // Remove breadcrumbs if disabled
  if (theme_get_setting('breadcrumb_display') == 0) {
    $vars['breadcrumb'] = '';
  }
	
 if (arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2))){
    unset($vars['page']['content']['system_main']['nodes']);
    unset($vars['page']['content']['system_main']['pager']);
    unset($vars['page']['content']['system_main']['no_content']);
  }
}

/**
 * Region preprocessing
 */
function fusion_ivigne_preprocess_region(&$vars) {
  static $grid;

  // Initialize grid info once per page
  if (!isset($grid)) {
    $grid = fusion_ivigne_grid_info();
  }

  // Set region variables
  $vars['region_style'] = $vars['fluid_width'] = '';
  $vars['region_name'] = str_replace('_', '-', $vars['region']);
  $vars['classes_array'][] = $vars['region_name'];
  if (in_array($vars['region'], array_keys($grid['regions']))) {
    // Set region full-width or nested style
    $vars['region_style'] = $grid['regions'][$vars['region']]['style'];
    $vars['classes_array'][] = ($vars['region_style'] == 'nested') ? $vars['region_style'] : '';
    $vars['classes_array'][] = $grid['name'] . $grid['regions'][$vars['region']]['width'];
    // Adjust & set region width
    if (!$grid['fixed'] && isset($grid['fluid_adjustments'][$vars['region']])) {
      $vars['fluid_width'] = ' style="width:' . $grid['fluid_adjustments'][$vars['region']] . '%"';
    }
  }

  // Sidebar regions receive common class, "sidebar".
  $sidebar_regions = array('sidebar_first', 'sidebar_second');
  if (in_array($vars['region'], $sidebar_regions)) {
    $vars['classes_array'][] = 'sidebar';
  }
  
}

/**
 * Block preprocessing
 */
function fusion_ivigne_preprocess_block(&$vars) {
  global $theme_info, $user;
  static $grid;

  // Exit if block is outside a defined region
  if (!in_array($vars['block']->region, array_keys($theme_info->info['regions']))) {
    return;
  }

  // Initialize grid info once per page
  if (!isset($grid)) {
    $grid = fusion_ivigne_grid_info();
  }

  // Increment block count for current block's region, add first/last position class
  $grid['regions'][$vars['block']->region]['count'] ++;
  $region_count = $grid['regions'][$vars['block']->region]['count'];
  $total_blocks = $grid['regions'][$vars['block']->region]['total'];
  $vars['classes_array'][] = ($region_count == 1) ? 'first' : '';
  $vars['classes_array'][] = ($region_count == $total_blocks) ? 'last' : '';
  $vars['classes_array'][] = $vars['block_zebra'];

  // Set a default block width if not already set by Fusion Apply
  $classes = implode(' ', $vars['classes_array']);

  // Special treatment for node_top and node_bottom regions.
  // They are rendered inside of the $content region, so they need to be adjusted to fit the grid properly.
  $assign_grid_units = ($vars['block']->region == 'node_top' || $vars['block']->region == 'node_bottom') ? FALSE : TRUE;
}


/**
 * Node preprocessing
 */
function fusion_ivigne_preprocess_node(&$vars) {
  // Add to array of handy node classes
  $vars['classes_array'][] = $vars['zebra'];                              // Node is odd or even
  $vars['classes_array'][] = (!$vars['teaser']) ? 'full-node' : '';       // Node is teaser or full-node

  // Make select regions available to node template.
  $node_region_list = array('node_top', 'node_bottom');
  $node_region_blocks = array();
  foreach($node_region_list as $region) {
    if ($list = fusion_ivigne_block_list($region)) {
      $node_region_blocks[$region] = _block_get_renderable_array($list);
    }
    $vars[$region] = isset($node_region_blocks[$region]) ? $node_region_blocks[$region] : array();
  }
  
  //Retrieve current breadcrumb
  $breadcrumbs = drupal_get_breadcrumb();
  //Add the title without link
  $breadcrumbs[] = $vars['node']->title;
  //OR add the title with a link
  $breadcrumbs[] = l($vars['node']->title, 'node/'.$vars['node']->nid);

  //Set the new breadcrumb
  drupal_set_breadcrumb($breadcrumbs);
}


/**
 * Comment preprocessing
 */
function fusion_ivigne_preprocess_comment(&$vars) {
  static $comment_odd = TRUE;                                                                             // Comment is odd or even

  // Add to array of handy comment classes
  $vars['classes_array'][] = $comment_odd ? 'odd' : 'even';
  $comment_odd = !$comment_odd;
}


/**
 * Views preprocessing
 * Add view type class (e.g., node, teaser, list, table)
 */
function fusion_ivigne_preprocess_views_view(&$vars) {
  $vars['css_name'] = $vars['css_name'] .' view-style-'. drupal_clean_css_identifier(strtolower($vars['view']->plugin_name));
}


/**
 * Search result preprocessing
 */
function fusion_ivigne_preprocess_search_result(&$vars) {
  static $search_zebra = 'even';

  $search_zebra = ($search_zebra == 'even') ? 'odd' : 'even';
  $vars['search_zebra'] = $search_zebra;
  $result = $vars['result'];
  $vars['url'] = check_url($result['link']);
  $vars['title'] = check_plain($result['title']);

  // Check for snippet existence. User search does not include snippets.
  $vars['snippet'] = '';
  if (isset($result['snippet']) && theme_get_setting('search_snippet')) {
    $vars['snippet'] = $result['snippet'];
  }

  $info = array();
  if (!empty($result['type']) && theme_get_setting('search_info_type')) {
    $info['type'] = check_plain($result['type']);
  }
  if (!empty($result['user']) && theme_get_setting('search_info_user')) {
    $info['user'] = $result['user'];
  }
  if (!empty($result['date']) && theme_get_setting('search_info_date')) {
    $info['date'] = format_date($result['date'], 'small');
  }
  if (isset($result['extra']) && is_array($result['extra'])) {
    // $info = array_merge($info, $result['extra']);  Drupal bug?  [extra] array not keyed with 'comment' & 'upload'
    if (!empty($result['extra'][0]) && theme_get_setting('search_info_comment')) {
      $info['comment'] = $result['extra'][0];
    }
    if (!empty($result['extra'][1]) && theme_get_setting('search_info_upload')) {
      $info['upload'] = $result['extra'][1];
    }
  }

  // Provide separated and grouped meta information.
  $vars['info_split'] = $info;
  $vars['info'] = implode(' - ', $info);

  // Provide alternate search result template.
  $vars['template_files'][] = 'search-result-'. $vars['module'];
}


/**
 * Header region override
 * Prints header blocks without region wrappers
 */
function fusion_ivigne_region__header($vars) {
  return $vars['content'];
}

/**
 * File element override
 * Sets form file input max width
 */
function fusion_ivigne_file($vars) {
  $vars['element']['#size'] = ($vars['element']['#size'] > 40) ? 40 : $vars['element']['#size'];
  return theme_file($vars);
}


/**
 * Custom theme functions
 */
function fusion_ivigne_theme() {
  return array(
    'grid_block' => array(
      'variables' => array('content' => NULL, 'id' => NULL),
    ),
  		'user_register_form' => array(
  				'render element'=>'form',
  				'template' =>'user-register',
  		),
  		'post_regist_form' => array(
  				'render element'=>'form',
  				'template' =>'post-regist',
  		),
  		'user_login' => array(
  				'render element'=>'form',
  				'template' =>'user-login',
  				//'preprocess functions' => array('fusion_ivigne_preprocess_user_login')
  		),
  );
}

/**
 * Returns a list of blocks.
 * Uses Drupal block interface and appends any blocks assigned by the Context module.
 */
function fusion_ivigne_block_list($region) {
  $drupal_list = array();
  if (module_exists('block')) {
    $drupal_list = block_list($region);
  }
  if (module_exists('context') && $context = context_get_plugin('reaction', 'block')) {
    $context_list = $context->block_list($region);
    $drupal_list = array_merge($context_list, $drupal_list);
  }
  return $drupal_list;
}

function fusion_ivigne_grid_block($vars) {
  $output = '';
  if ($vars['content']) {
    $id = $vars['id'];
    $output .= '<div id="' . $id . '" class="' . $id . ' block">' . "\n";
    $output .= '<div id="' . $id . '-inner" class="' . $id . '-inner gutter">' . "\n";
    $output .= $vars['content'];
    $output .= '</div><!-- /' . $id . '-inner -->' . "\n";
    $output .= '</div><!-- /' . $id . ' -->' . "\n";
  }
  return $output;
}


/**
 * Generate initial grid info.
 */
function fusion_ivigne_grid_info() {
  global $theme_key;

  $grid = &drupal_static(__FUNCTION__);
  if (isset($grid)) {
    return $grid;
  }

  $grid = array();
  if (theme_get_setting('responsive_enabled') && module_exists('fusion_accelerator')) {
    $grid['type'] = 'responsive';
    $grid['name'] = 'grid' . theme_get_setting('responsive_columns') . '-';
    $grid['fixed'] = TRUE;
    $grid['width'] = theme_get_setting('responsive_columns');
  } else {
    $grid['name'] = substr(theme_get_setting('theme_grid'), 0, 7);
    $grid['type'] = substr(theme_get_setting('theme_grid'), 7);
    $grid['fixed'] = (substr(theme_get_setting('theme_grid'), 7) != 'fluid') ? TRUE : FALSE;
    $grid['width'] = (int)substr($grid['name'], 4, 2);
  }

  // @todo - eventually sidebar widths should be per responsive layout, but this isn't possible
  // the way Fusion currently handles "adjusted regions".
  $grid['sidebar_first_width'] = (fusion_ivigne_block_list('sidebar_first')) ? theme_get_setting('sidebar_first_width') : 0;
  $grid['sidebar_second_width'] = (fusion_ivigne_block_list('sidebar_second')) ? theme_get_setting('sidebar_second_width') : 0;

  $grid['regions'] = array();
  $regions = array_keys(system_region_list($theme_key, REGIONS_VISIBLE));
  $nested_regions = theme_get_setting('grid_nested_regions');
  $adjusted_regions = theme_get_setting('grid_adjusted_regions');
  foreach ($regions as $region) {
    $region_style = 'full-width';
    $region_width = $grid['width'];
    if ($region == 'sidebar_first' || $region == 'sidebar_second') {
      $region_width = ($region == 'sidebar_first') ? $grid['sidebar_first_width'] : $grid['sidebar_second_width'];
    }
    if ($nested_regions && in_array($region, $nested_regions)) {
      $region_style = 'nested';
      if ($adjusted_regions && in_array($region, array_keys($adjusted_regions))) {
        foreach ($adjusted_regions[$region] as $adjacent_region) {
          $region_width = $region_width - $grid[$adjacent_region . '_width'];
        }
      }
    }
    $grid['regions'][$region] = array('width' => $region_width, 'style' => $region_style, 'total' => count(fusion_ivigne_block_list($region)), 'count' => 0);
  }

  // Adjustments for fluid width regions & groups
  $grid['fluid_adjustments'] = array();
  // Regions
  $adjusted_regions_fluid = (theme_get_setting('grid_adjusted_regions_fluid')) ? theme_get_setting('grid_adjusted_regions_fluid') : array();
  foreach (array_keys($adjusted_regions_fluid) as $adjusted_region) {
    $width = $grid['width'];
    foreach ($adjusted_regions_fluid[$adjusted_region] as $region) {
      $width = $width - $grid['regions'][$region]['width'];         // Subtract regions outside parent group to get correct parent width
    }
    $grid['fluid_adjustments'][$adjusted_region] = round(($grid['regions'][$adjusted_region]['width'] / $width) * 100, 2);
  }
  // Groups
  $adjusted_groups_fluid = (theme_get_setting('grid_adjusted_groups_fluid')) ? theme_get_setting('grid_adjusted_groups_fluid') : array();
  foreach (array_keys($adjusted_groups_fluid) as $adjusted_group) {
    $width = 100;
    foreach ($adjusted_groups_fluid[$adjusted_group] as $region) {
      $width = $width - $grid['fluid_adjustments'][$region];         // Subtract previously calculated sibling region fluid adjustments
    }
    $grid['fluid_adjustments'][$adjusted_group] = $width;            // Group gets remaining width
  }

  return $grid;
}


/**
 * Theme paths function
 * Retrieves parent and current theme paths in parent-to-current order.
 */
function fusion_ivigne_theme_paths($theme) {
  $base_themes = system_find_base_themes(list_themes(), $theme);
  foreach ($base_themes as $key => $base_theme) {
    $base_themes[$key] = drupal_get_path('theme', $key);     // Base theme paths
  }
  $base_themes[$theme] = drupal_get_path('theme', $theme);   // Current theme path
  return $base_themes;
}

function fusion_ivigne_form_alter(&$form, $form_state, $form_id){
  switch ($form_id){
	  case 'comment_node_article_form':
	  {
			//dpm($form);
			$form['author']['_author']['#title'] = t('用户名');
			$form['actions']['preview']['#access'] = FALSE;
			$form['actions']['submit']['#value'] = t('发表评论');
		  }break;
		  case 'search_block_form':
		  {
			$form['actions']['submit']['#value'] = t('搜索');
			$form['search_block_form']['#attributes'] = array(
				'title' => t('输入搜索内容'),
				'value' => t('寻找你喜欢的内容或人'),
				'size' => 20,
				'onfocus' => "if (this.value == '寻找你喜欢的内容或人') {this.value = '';}",
	      'onblur' => "if (this.value == '') {this.value = '寻找你喜欢的内容或人';}"
			);
			$form['search_block_form']['#size'] = 15;
	  }break;
	  case 'user_login':
	  {
			$form['name']['#title'] = t('电子邮箱/用户名');
			unset($form['name']['#description']);
			$form['name']['#field_suffix'] = '<i><a title="your email address"></a></i>';
			$form['pass']['#title'] = t('密码');
			$form['pass']['#field_suffix'] = l(t('忘记密码？'), 'user/password', array('html' => TRUE, 'attributes' => array('class' => array(''), 'title' => t('忘记密码？'))));
			unset($form['pass']['#description']);
			
			$form['actions']['submit']['#value'] = t('登录');
			$form['#submit'][] = 'ivigne_user_login_submit';
		}break;
		case 'user_register_form':
		{
			$form['account']['mail']['#title'] = t('输入电子邮箱');
			$form['account']['mail']['#field_suffix'] = '<i><a title="your email address"></a></i>';
			unset($form['account']['mail']['#description']);
			unset($form['account']['pass']['#description']);
			$form['actions']['submit']['#value'] = t('注册');
			$form['#submit'][] = 'ivigne_user_register_submit';
	  }break;
		case 'post_regist_form':
		{
			$form['account']['name']['#title'] = t('用户名');
			$form['account']['name']['#field_suffix'] = '<i><a title="your user name"></a></i>';
			$form['picture']['ivigne_pic_upload'] =  array(
		    '#markup' => '<a class="" onclick="document.getElementById(\'edit-picture-upload\').click();">更改头像</a>',
		    '#weight' => 2,
		  );
			unset($form['profile_main']['#title']);
		}break;
	  case 'user_pass':
	  {
		//dpm($form);
		
	  }break;	  
	  default:
	  //drupal_set_message($form_id);
	  break;
  }
}

function ivigne_user_register_submit($form, &$form_state) {
	$_SESSION['post_register_access'] = TRUE;
	$form_state['redirect'] = 'user/register/post';
}

function ivigne_user_login_submit($form, &$form_state) {
	$form_state['redirect'] = '';
}
function fusion_ivigne_breadcrumb($vars) {
	if(!drupal_is_front_page()){
		$breadcrumb = array();
		 
		if (arg(0) == 'node' && is_numeric(arg(1))) {
			$node = node_load(arg(1));
			$language = 'und';
			switch($node->type){
				case('article'):
					{
						$breadcrumb[] = l(t('探索'), 'article');
						foreach ($node->field_article_categories[$language] as $delta => $value) {
							$term = taxonomy_term_load($value['tid']);
							$breadcrumb[] = l($term->name, 'article-list-page/'.$term->name);
							unset($term);
						}
						 
						$title = drupal_get_title();
						if (!empty($title)) {
							$breadcrumb[] = l($title, 'article/'.arg(1));
							unset($title);
						}
					}
					break;
				case('event'):
					{
						$breadcrumb[] = l(t('活动'), 'event');
						$node_f = $node->field_event_city;
						if($node_f!=null){
							foreach ($node->field_event_city[$language] as $delta => $value) {
								$term = taxonomy_term_load($value['tid']);
								$breadcrumb[] = l($term->name, 'event-list-page/'.$term->name);
								unset($term);
							}
						}
						 
						$title = drupal_get_title();
						if (!empty($title)) {
							$breadcrumb[] = l($title, 'event/'.arg(1));
							unset($title);
						}
					}
					break;
					break;
				default:break;
			}
			 
			return '<div class="breadcrumbs-article">'. implode(' &gt; ', $breadcrumb).'</div>';
		}
	}
}

function fusion_ivigne_preprocess_taxonomy_term(&$variables) {
  $variables['view_mode'] = $variables['elements']['#view_mode'];
  $variables['term'] = $variables['elements']['#term'];
  $term = $variables['term'];

  $uri = entity_uri('taxonomy_term', $term);
  $variables['term_url']  = url($uri['path'], $uri['options']);
  $variables['term_name'] = check_plain($term->name);
  $variables['page']      = $variables['view_mode'] == 'full' && taxonomy_term_is_page($term);

  // Flatten the term object's member fields.
  $variables = array_merge((array) $term, $variables);
  //$variables['content']=$term->vid;
  
  switch($term->vid){
  case(2): $view_name = 'article_list_page';break; //article categories
  case(3): $view_name = 'article_kw_list_page';break;//article keywords
  case(6): $view_name = 'event_list_category'; break;//event categories
  case(7): $view_name = 'event_list_city'; //event cities
  default: $view_name = '';break;
  }
  
  $variables['content'] = array();
  $variables['content'] = views_embed_view($view_name, 'page', $term->name);

  // field_attach_preprocess() overwrites the $[field_name] variables with the
  // values of the field in the language that was selected for display, instead
  // of the raw values in $term->[field_name], which contain all values in all
  // languages.
  field_attach_preprocess('taxonomy_term', $term, $variables['content'], $variables);

  // Gather classes, and clean up name so there are no underscores.
  $vocabulary_name_css = str_replace('_', '-', $term->vocabulary_machine_name);
  $variables['classes_array'][] = 'vocabulary-' . $vocabulary_name_css;

  $variables['theme_hook_suggestions'][] = 'taxonomy_term__' . $term->vocabulary_machine_name;
  $variables['theme_hook_suggestions'][] = 'taxonomy_term__' . $term->tid;
}

function fusion_ivigne_comment_form_alter(){
	
}